package com.baizhi.cmfz.controller;

import com.baizhi.cmfz.annotation.LogAnnotation;
import com.baizhi.cmfz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * This is a Class.
 *
 * @author zhanglh
 * @date 2019/09/11
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("all")
    @LogAnnotation(value = "查找所有用户")
    public Map selectAllUser(int page, int limit, String userName) {
        return userService.selectAllUser(page, limit, userName);
    }

    @RequestMapping("updateStatus")
    @LogAnnotation(value = "更改用户状态", type = "update")
    public boolean updateStatus(int userId, int userStatus) {
        return userService.updateStatus(userId, userStatus) > 0;
    }

    //数据展示 多线程
    @RequestMapping("showData")
    @LogAnnotation(value = "展示所有数据统计信息")
    public Map showData() throws InterruptedException {
        long start = System.currentTimeMillis();
        Map map = userService.showData();
        long end = System.currentTimeMillis();
        return map;
    }

    //数据展示
    @RequestMapping("show")
    @LogAnnotation(value = "展示所有用户信息")
    public Map showData2() {
        Map<String, List<Map>> map = new HashMap<>();
        long start = System.currentTimeMillis();
        map.put("sex", userService.showSexData());
        map.put("date", userService.showDateData());
        map.put("province", userService.showProvinceData());
        long end = System.currentTimeMillis();
        return map;
    }

}
